import dayjs from "dayjs";
import { Service } from "cl-admin";
import BaseService from "@/service/base";
@Service("deposit")
class Deposit extends BaseService {
	// 全部列表
	list() {
		return Promise.resolve([
			/* 数据列表 */
		]);
	}
	// 分页列表
	page() {
		return Promise.resolve([
			/* 数据列表 */
		]);
	}
	// 客户定金明细列表
	cusList(params) {
		return this.$get("/customerdepositlist", { params });
	}
	canCancel(data) {
		if (!data.create_at) return false;
		let now = dayjs();
		let date = dayjs(data.create_at).add(2, "day");
		return now.isBefore(date);
	}
	// 指定客户的定金列表
	listuse(params) {
		return this.$get("/listusedeposit", { params }).then(res => {
			return res.map(v => ({ ...v, can_cancel: this.canCancel(v) }));
		});
	}
	// 客户各种定金总金额
	userInfo(params) {
		return this.$get("/getuserdepositinfo", { params });
	}
	// 金额配置列表;
	configlists(params) {
		return this.$get("/configlists", { params });
	}
	// 预约定金 - 添加（线下）
	add(params) {
		return this.$post("/add", params);
	}
	// 预约定金 - 编辑
	edit(params) {
		return this.$post("/edit", params);
	}
	// 取消定金
	cancel(dep_id) {
		return this.$post("/depositcancel", { dep_id });
	}
	// 退回定金申请
	refund(params) {
		return this.$post("/refundusedeposit", params, {
			// headers: {
			// 	"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
			// }
		});
	}
	// 我的收款码
	mycode(params) {
		return this.$get("/mycode", { params });
	}
	// 收取定金-收款报表
	orderStatement({ date, dept_ids = [], bra_id = [], ...args }) {
		let params = {
			...args,
			dept_id: dept_ids.join(),
			bra_id: bra_id.join()
		};
		if (date && date.length) {
			params.btime = date[0];
			params.etime = date[1];
		}
		return this.$get("/orderstatement", { params }).then(res => {
			return {
				list: res,
				pagination: {
					...params,
					total: res.length
				}
			};
		});
	}
	// 定金 - 收款列表
	orderList({ date, size, dept_ids = [], bra_id = [], ...args }) {
		let params = {
			pagesize: size,
			...args,
			dept_id: dept_ids.join(),
			bra_id: bra_id.join()
		};
		if (date && date.length) {
			params.btime = date[0];
			params.etime = date[1];
		}
		return this.$get("/orderlists", { params }).then(res => {
			console.log(res);
			return {
				list: res?.lists?.map?.(v => {
					let data_set = {};
					try {
						data_set = JSON.parse(v.data_set);
					} catch {}
					return { ...v, data_set };
				}),
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	// 我的定金列表
	mine({ time, ptime, gtime, size, bra_id = [], ...args }) {
		let params = {
			pagesize: size,
			bra_id: bra_id.join(),
			...args
		};
		// 定金日期
		if (time && time.length) {
			params.btime = time[0];
			params.etime = time[1];
		}
		// 推送时间
		if (ptime && ptime.length) {
			params.ptime_s = ptime[0];
			params.ptime_e = ptime[1];
		}
		// 接收时间
		if (gtime && gtime.length) {
			params.gtime_s = gtime[0];
			params.gtime_e = gtime[1];
		}
		return this.$get("/mineDeposit", { params }).then(res => {
			return {
				list: res.lists,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	// 推送定金
	push(params) {
		return this.$get("/pushDeposit", { params });
	}

	// 接收定金
	receive(params) {
		return this.$get("/getDeposit", { params });
	}
	// 拒收定金
	refuse(params) {
		return this.$post("/refuseDeposit", params);
	}
	// 退回定金列表
	refundlist({ time, time1, time2, size, dept_ids, bra_id = [], ...args }) {
		let params = {
			...args,
			pagesize: size,
			dept_id: dept_ids.join(),
			bra_id: bra_id.join()
		};
		// if (dept_ids && dept_ids.length) {
		// 	params.dept_id = last(dept_ids);
		// }
		// 定金日期
		if (time && time.length) {
			params.time_from = time[0];
			params.time_to = time[1];
		}
		// 退定
		if (time1 && time1.length) {
			params.time1_from = time1[0];
			params.time1_to = time1[1];
		}
		// 打款
		if (time2 && time2.length) {
			params.time2_from = time2[0];
			params.time2_to = time2[1];
		}
		return this.$get("/depositrefundlist", { params }).then(res => {
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	//打款
	refundsuccess(params) {
		return this.$post("/refundsuccess", params);
	}
	// 查看定金申请信息
	getrefunduse(params) {
		return this.$get("/getrefundusedeposit", { params });
	}
	// 客户定金金额
	operaterefunduse(params) {
		return this.$post("/operaterefundusedeposit", params);
	}
	// 需增加查询支付接果接口
	query(params) {
		return this.$post("/query", params);
	}
	depositre(params) {
		return this.$post("/depositrefundsuccess", params);
	}

	// 一键打款
	togetherPayment(params) {
		return this.$post("/togetherPayment", params);
	}
	// 公众号收款码
	createwxcode(params) {
		return this.$get("/createwxcode", { params });
	}
	// 支付编码
	createtestpay(params) {
		return this.$get("/createtestpay", { params });
	}
	// 修改门店和员工
	editDeposit(params) {
		return this.$post("/editDeposit", params);
	}
	getBillList() {
		return this.$get("/getBillList", {});
	}

	// 15天未到店
	fifteenDay({ size, ...args }) {
		let params = {
			search_type: 0,
			pagesize: size,
			...args
		};
		return this.$get("/fifteenDay", { params });
		return this.$get("/fifteenDay", { params }).then(res => {
			return {
				list: res.data ?? [],
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	// 收款记录
	allBillList({ size, timeList, ...args }) {
		let params = {
			begin_time: timeList[0],
			end_time: timeList[1],
			...args,
			page_size: size
		};
		return this.$get("/allBillList", { params }).then(res => {
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	// 添加收款记录
	addBill(params) {
		return this.$post("/addBill", params);
	}
	// 删除收款记录
	delBill(params) {
		return this.$post("/delBill", params);
	}
}
export default Deposit;
